package com.example.demo.SecurityConfig;

import com.example.demo.Data.User.UserBo;
import com.example.demo.Data.User.UserDo;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component
public class UserDetailServiceImpl implements UserDetailsService
{
    @Override
    public UserDetails loadUserByUsername(String user_id) throws UsernameNotFoundException
    {
        UserBo userBo = new UserBo(UserDo.findUserByID(Long.parseLong(user_id)));
        if (userBo.getPassword() == null)
            throw new UsernameNotFoundException("Incorrect user ID.");
        return userBo;
    }
}
